package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.TechDeviceParam;
import com.sailfish.springbootdemo.service.db1.PcbaDeviceTypeService;
import com.sailfish.springbootdemo.service.db1.TechDeviceParamService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/techDeviceParam")
@CrossOrigin
public class TechDeviceParamController {

    @Autowired
    private TechDeviceParamService techDeviceParamService;

    @Autowired
    private PcbaDeviceTypeService pcbaDeviceTypeService;

    @PostMapping("/getAllTechDeviceParam")
    public Result getAllPcbaDeviceParam(HttpServletRequest request, Integer pcbaDeviceTypeId, Integer techDeviceParamTypeId, String searchTechDeviceParamName) {
        try {
            return ResultUtil.success(techDeviceParamService.getAllTechDeviceParam(request, pcbaDeviceTypeId, techDeviceParamTypeId, searchTechDeviceParamName));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/analysisTechDeviceParamExcel")
    public Result analysisPcbaDeviceParamExcel(MultipartFile file) {
        return techDeviceParamService.analysisTechDeviceParamExcel(file);
    }

    @PostMapping("/deleteById")
    public Result deleteById(Integer techDeviceParamId) {
        return techDeviceParamService.deleteById(techDeviceParamId);
    }

    @PostMapping("/addOrUpdateTechDeviceParam")
    public Result addOrUpdateTechDeviceParam(TechDeviceParam techDeviceParam, String mode) {
        return techDeviceParamService.addOrUpdateTechDeviceParam(techDeviceParam, mode);
    }

    @PostMapping("/changeActualEqualDeclare")
    public Result changeActualEqualDeclare(Integer techDeviceParamId) {
        return techDeviceParamService.changeActualEqualDeclare(techDeviceParamId);
    }

    @PostMapping("/exportTechDeviceParamExcel")
    public Result exportTechDeviceParamExcel() {
        return techDeviceParamService.exportTechDeviceParamExcel();
    }

    @PostMapping("/getTechDeviceParamByKey")
    public Result getTechDeviceParamByKey(String techDeviceParamKey) {
        return techDeviceParamService.getTechDeviceParamByKey(techDeviceParamKey);
    }
}
